package com.hitqz.robot.api.business.vo;

import cn.hutool.core.util.StrUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.Date;

/**
 * @author wengyx
 * @date 2024/8/7
 * 检测结果
 */
@Data
@Schema(description = "巡检结果")
public class PatrolResultVo {
    @Schema(description = "id")
    private Long id;
    @Schema(description = "工单id")
    private Integer ticketsId;
    @Schema(description = "节点名称")
    private String roomName;
    @Schema(description = "设备名称")
    private String devName;
    @Schema(description = "检测项名称")
    private String itemName;
    @Schema(description = "检测项id")
    private String itemId;

    @Schema(description = "检测时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date checkTime;
    @Schema(description = "结果值")
    private String showValue;

    @Schema(description = "正常值")
    private String normalValue;

    @Schema(description = "媒体地址 根据后缀处理.jpg .jpeg .wav .mp4")
    private String mediaUrl;
    @Schema(description = "视觉处理媒体地址 根据后缀处理.jpg .jpeg .wav .mp4")
    private String visionMediaUrl;
    @Schema(description = "状态 0-未检测 1-正常 2-异常 3-视觉识别失败")
    private Integer status;
    @Schema(description = "上传状态 0-未上传 1-上传完成 2-上传失败")
    private Integer uploadStatus;
    @Schema(description = "审核状态 0-未审核 1-已审核")
    private Integer auditStatus;
    @Schema(description = "审核时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date auditTime;
    @Schema(description = "审核人")
    private String auditor;
    @Schema(description = "审核意见")
    private String auditRemark;

    // 编码，避免#等特殊符号
    public String getMediaUrl() {
        if (StrUtil.isNotBlank(mediaUrl)){
            return URLEncoder.encode(mediaUrl, StandardCharsets.UTF_8);
        }
        return mediaUrl;
    }
    // 编码，避免#等特殊符号
    public String getVisionMediaUrl() {
        if (StrUtil.isNotBlank(visionMediaUrl)){
            return URLEncoder.encode(visionMediaUrl, StandardCharsets.UTF_8);
        }
        return visionMediaUrl;
    }
}
